<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>工程材料需求申请单管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="../../../resources/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../../resources/css/style.css" media="all">
    <style>
        .layui-form-label{width: 100px; height: 20px;}
        .layui-form-select{width: 190px;}
        #gonghuoshijian{ width: 100%;}
        .addUser input{width: 86%;}
        .layui-form-select{width: 100%!important;}
        .layui-form-select input{width: 100%;}
        .layui-form-item{padding-left: 0;}
        .layui-form-item .layui-input-inline{width: 73%!important;}
        .masksx{width: 800px;}
        .material{display: flex;justify-content: flex-start;padding-left: 15px;padding-right: 77px;margin-bottom: 8px;width: 100%;margin-left: 55px;}
        .material label{float: left;height: 38px;line-height: 38px; display: inline-block;}
        ._mater{width: 49%;margin-left: 30px;}
        .layui-form-select .layui-input{padding-right: 0;}
        ._materwarp{width: 43%;}
        .masksx .forms{padding: 0;}
        .material ._mater_input{width: 10%;}
        ._mater_lab{margin:0 20px;}
        .addTo{background-color: #86B1FC;color: #FFF; width: 10px;height: 10px;display: none}
        .materialone .addTo{display:inline;}
        .mater_btn{margin: 6px 0 0 6px;}
        .material_C{width: 100px;text-align: justify;}
        .material_C:after{content:'';width: 100%;display: inline-block;}
        .materialone .mater_btn{display: none;}
        .layui-form-selectup dl{top: -184px;}
        @media screen and (max-width: 750px){
            .MOVE_queryon .layui-form-item {
                width: 80%;
            }
            .layui-form-item{padding: 0;}
            .MOVE_footer{text-align: right;}
            .MOVE_footer a{color: #FFF;font-size: 20px;line-height: 30px;
                padding: 10px;background-color: #F5A721;height: 100%;position: absolute;right: 0;}
        }
        .layui-form-pane .layui-input-inline{width: 80%;}
        .titles{text-align: center;margin: 0;font-size: 20px;}
        .xuanzhong .layui-input-block{margin-left: 0;}
        .beixuan table th{width: 33.333%;}
        .masksx{height: 80%;}
        .layui-table tbody th {text-align: center;}
        .beixuan tr th{width: 25%!important;}
    </style>
</head>
<body>
<div class="_PC">
    <form class="layui-form layui-form-pane" id="form_7grid" action="" lay-filter="hetong">
        <div class="formTop layui-row">
            <div class="layui-inline layui-col-lg3 layui-col-md3 layui-col-xs3">
                <div class="layui-input-inline" style="width: 80%;">
                    <input type="text" name="username" lay-verify="required" placeholder="项目名称" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline layui-col-lg3 layui-col-md3 layui-col-xs3">
                <div class="layui-input-inline">
                    <input type="text" class="layui-input" id="test-limit3" placeholder="请输入供料开始日期">
                    <div class="icons">

                    </div>
                </div>
            </div>
            <div class="layui-inline layui-col-lg3 layui-col-md3 layui-col-xs3">
                <div class="layui-input-inline">
                    <input type="text" class="layui-input" id="test-limit4" placeholder="请输入供料结束日期">
                    <div class="icons">

                    </div>
                </div>
            </div>
            <div class="layui-inline layui-col-lg3 layui-col-md3 layui-col-xs3">
                <button class="layui-btn" type="button"  onclick="query()">查询</button>
            </div>

        </div>
        <table id="demo" lay-filter="test"></table>
        <script type="text/html" id="barDemo">
            <a class="layui-btn layui-btn-sm layui-btn-normal fahuo quanxian" lay-event="shenqing" QX="api/supply/builFeedManagerVali.do">发货</a>
            <!--<a class="layui-btn layui-btn-danger layui-btn-sm chakan" lay-event="look">查看</a>-->

            <!--<a class="layui-btn layui-btn-danger layui-btn-sm" lay-event="edit">编辑</a>-->
        </script>
        <!--<script type="text/html" id="titleTpl">-->

        <!--<span>{{times(1510635999999)}}</span>-->

        <!--</script>-->
    </form>
    <div id="demo7"></div>
    <a class="dayin" type="button" id="dlink"  style="float: right; position: fixed; right: 50px; bottom: 50px; z-index: 999;"></a>

    <div class="mask">
        <div class="masksx">
            <div class="title"><span class="titleL">发货</span><span class="close">×</span></div>
            <div class="forms">
                <form class="layui-form addUser" method="post" action="">
                    <div class="titles">需求申请单</div>
                    <div class="xuanzhong">
                        <table class="layui-table">
                            <thead>
                                <tr>
                                    <th>
                                        <div class="layui-form-item" pane="">
                                            <div class="layui-input-block">

                                                <input type="checkbox" name="like1[write]" lay-filter="allChoose" lay-skin="primary" title='选中' class="quanxuan">       <!--checked=""   是否被选中-->

                                            </div>
                                        </div>
                                    </th>
                                    <th>材料名</th>
                                    <th>规格</th>
                                    <th>申请数量</th>
                                    <th>审核数量</th>
                                    <th>计量单位</th>

                                </tr>
                            </thead>
                            <tbody>
                                <!--<tr>-->
                                    <!--<th>-->
                                        <!--<div class="layui-form-item" pane="">-->
                                            <!--<div class="layui-input-block">-->
                                                <!--<input type="checkbox" name="like1[write]" lay-filter="filter" lay-skin="primary" title='' checked="">-->
                                            <!--</div>-->
                                        <!--</div>-->
                                    <!--</th>-->
                                    <!--<th>铸铁井盖</th>-->
                                    <!--<th>100*200</th>-->
                                    <!--<th>3</th>-->
                                </tr>
                            </tbody>
                        </table>
                    </div>
                    <div class="beixuan">
                        <div class="titles">材料供应单</div>
                        <table class="layui-table">
                            <thead>
                            <tr>
                                <th>材料名</th>
                                <th>规格</th>
                                <th>发货数量</th>
                                <th>计量单位</th>

                            </tr>
                            </thead>
                            <tbody>
                                <!--<tr>-->
                                    <!--<th>铸铁井盖</th>-->
                                    <!--<th>100*200</th>-->
                                    <!--<th>-->
                                        <!--<input type="number" class="inputs" lay-verify="required"/>-->
                                    <!--</th>-->
                                <!--</tr>-->
                            </tbody>
                        </table>
                    </div>

                    <div class="_submit" style="text-align: right;">
                        <button class="layui-btn layui-btn-sm layui-btn-disabled tijiao" lay-submit lay-filter="_subm" style="margin-right: 50px;">发货</button>
                    </div>

                </form>

            </div>

        </div>

    </div>

</div>



<script src="../../../resources/layui/layui.js" charset="utf-8"></script>
<script src="../../../resources/js/style.js"></script>
<script src="../../../resources/js/api.js"></script>
<script>

    function query() {
        layui.use(['form', 'layedit', 'laydate','table','element'], function() {
            var form = layui.form
                , table = layui.table;
            var pronName=$("[name='username']").val();
            var begintime=$('#test-limit3').val();
            var endtime=$('#test-limit4').val();


            if(!AntiSqlValid(pronName)){
                if(lbq('api/matperson/loadGysFeedSel.do')){
                    API.cailiaoApply({'type':'a','proName':pronName,'begintime':begintime,'endtime':endtime,'p':getCookie('yanzheng')})
                }

            }else {
                layer.msg('请勿输入特殊符号');
            };
        })

    }

    function daochu(n) {
        layui.use(['form', 'layedit', 'laydate'], function() {
            var form = layui.form
                , layer = layui.layer
                , layedit = layui.layedit
                , laydate = layui.laydate;


            layer.open({
                type: 2,
                title: '合同打印预览',
                shadeClose: true,
                shade: 0.8,
                area: ['90%', '90%'],
                content: [urls+'/ureport/preview?_u=file:建投通讯管线有限公司收料单.ureport.xml']

            });
        })
    }



    layui.use(['form', 'layedit', 'laydate','table','element','laypage','flow'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laydate = layui.laydate
            ,table=layui.table
            ,laypage=layui.laypage
            ,flow=layui.flow
            ,element=layui.element;
        jiazais();          //尚未获取到数据时的加载动画

        laydate.render({
            elem: '#gonghuoshijian' //指定元素
            ,type: 'datetime'
        });

        $(document).on('click','.mater_btn',function () {
            $(this).parent().remove();
        });

        $('.close').click(function () {     //遮罩层隐藏
            $('.mask').hide();
        });

        dayintishi('.dayin');           //移入图标时显示的打印图标

        //日期控件
        laydate.render({
            elem: '#date'
            ,type: 'datetime'
        });
        laydate.render({
            elem: '#date1'
            ,type: 'datetime'
        });

        //执行渲染
        if(lbq('api/matperson/loadGysFeedSel.do')) {
            API.cailiaoApply({'type': 'a', 'p': getCookie('yanzheng')});
        };
        //前后若干天可选，这里设置不能选过去的日期      最远可选1000天之后
        panduanshijiantow('#test-limit3','#test-limit4',1000,1000,'.layui-btn-normal');     //查询 开始结束时间判断
        //监听全选
        form.on('checkbox(allChoose)', function(data){
            //console.log(data.elem); //得到checkbox原始DOM对象
            //console.log(data.elem.checked); //是否被选中，true或者false
            //console.log(data.value); //复选框value值，也可以通过data.elem.value得到
            //console.log(data.othis); //得到美化后的DOM对象
            var child = $(data.elem).parents('table').find('tbody input[type="checkbox"]');         //找到tbody下的所有多选框
            child.each(function(index, item){                             //循环每个参数item  每个多选框
                item.checked = data.elem.checked;                         //所有多选框  选中或取消选中
//                $(item).trigger('click');
            });
            form.render('checkbox');                                      //局部刷新多选框  保持页面操作一致性
            $('.beixuan table tbody').html('');
            $('.xuanzhong tbody tr').each(function () {
                var chuandi=new Object();
                var _this=$(this);
                chuandi.xuan=$(_this).children().children().children().children('[name="like1[write]"]');
                //console.log(chuandi.xuan)
                chuandi.jia=$(_this).attr('idang');
                chuandi.id=$(_this).attr('id');
                chuandi.mat_id=$(_this).attr('mat_id');
                chuandi.names=_this.attr('names');
                chuandi.guige=_this.attr('guiges');
                chuandi.num=_this.attr('nums');
                chuandi.danwei=$(_this).attr('danwei');
//               alert(chuandi.guige)
                $('.tijiao').removeClass('layui-btn-disabled');
                /*徐  12/26改动  思路 点击时 先清空下部已加载部分 而后再添加*/
                if(data.elem.checked){          //如果多选框被选中  给下半部添加内容
                    //console.log(chuandi.xuan.is(':checked'),'>>>>>>>><<<<<<<<<<>>>>>>')
//                    //console.log(chuandi.xuan.is(':checked'))
//                    if(chuandi.xuan.is(':checked')) {
////                       alert('我已经被选中了')
//                        return;
//                    }
                    $('.beixuan table tbody').append('<tr id="'+chuandi.id+'" mat_id="'+chuandi.mat_id+'" idang="'+chuandi.jia+'">' +
                        '                                    <th class="names">'+chuandi.names+'</th>' +
                        '                                    <th class="guige">'+chuandi.guige+'</th>' +
                        '                                    <th class="nums">' +
                        '                                        <input type="number" class="inputs" lay-verify="required" value="'+chuandi.num+'"/>' +
                        '                                        <input type="hidden" class="numson" lay-verify="required" value="'+chuandi.num+'"/>' +
                        '                                    </th>' +
                        '                                    <th class="guige">'+chuandi.danwei+'</th>' +

                        '                                </tr>')
                }else{                          //否则循环下半部所有的tr删除对应的tr
                    $('.beixuan table tbody tr').each(function () {
                        if($(this).attr('id')==chuandi.id){
                            $(this).remove();
                        };
                    });
                };
            });
            return;
        });
        //监听单个点击多选
        form.on('checkbox(filter)', function(data){
            //console.log(data.elem); //得到checkbox原始DOM对象
            //console.log(data.elem.checked); //是否被选中，true或者false
            //console.log(data.value); //复选框value值，也可以通过data.elem.value得到
            //console.log(data.othis); //得到美化后的DOM对象
            var _this=data.othis;
            var chuandi=new Object();
            chuandi.jia=$(_this).parents('tr').attr('idang');
            chuandi.id=$(_this).parents('tr').attr('id');
            chuandi.mat_id=$(_this).parents('tr').attr('mat_id');
            chuandi.names=_this.parents('th').next().text();
            chuandi.guige=_this.parents('th').next().next().text();
            chuandi.num=_this.parents('th').next().next().next().text();
            chuandi.danwei=$(_this).parents('tr').attr('danwei');
            //console.log(chuandi)
            var as=true;
            var child = $(data.elem).parents('table').find('thead input[type="checkbox"]');         //找到tbody下的所有多选框
            //console.log(child,'>>>>>>LLLLLLLLLLL')
            $('.tijiao').removeClass('layui-btn-disabled');
            $('tbody [name="like1[write]"]').each(function () {
                if(!$(this).is(':checked')){
                    as=false;
                    return false;
                }else{
                    as=true;
                };
            });
            if(as){
                child.each(function(index, item){                             //循环每个参数item  每个多选框
                    item.checked = data.elem.checked;                         //所有多选框  选中或取消选中
                });
            }else{
                child.each(function(index, item){                             //循环每个参数item  每个多选框
                    item.checked = false                         //所有多选框  选中或取消选中
                });
            }
            form.render();
            //console.log($(data.elem).parent(), 'is i======================== parent =')
            if(data.elem.checked){          //如果多选框被选中  给下半部添加内容
                $('.beixuan table tbody').append('<tr id="'+chuandi.id+'" mat_id="'+chuandi.mat_id+'" idang="'+chuandi.jia+'">' +
                    '                                    <th class="names">'+chuandi.names+'</th>' +
                    '                                    <th class="guige">'+chuandi.guige+'</th>' +
                    '                                    <th class="nums">' +
                    '                                        <input type="number" class="inputs" lay-verify="required" value="'+chuandi.num+'"/>' +
                    '                                        <input type="hidden" class="numson" lay-verify="required" value="'+chuandi.num+'"/>' +
                    '                                    </th>' +
                    '                                    <th class="guige">'+chuandi.danwei+'</th>' +

                    '                                </tr>')
            }else{                          //否则循环下半部所有的tr删除对应的tr
                $('.beixuan table tbody tr').each(function () {
                    if($(this).attr('id')==chuandi.id){
                        $(this).remove();
                    };
                });
            };
        });
        $(document).on('blur','[type="number"]',function () {
            if($(this).val()<0){
                layer.msg('数量不能小于0');
                $(this).val(0);
            };
        });
        var uuids='';       //接受合同id;
        var dizhi='';       //接受合同地址;
        //监听工具条
        table.on('tool(test)', function(obj){ //注<span class="maohao">：</span>tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值
            var tr = obj.tr; //获得当前行 tr 的DOM对象
            if(layEvent === 'shenqing'){ //发货
                //do somehing
                //console.log(obj)
                if($('.quanxuan').is(':checked')) {                 //取消选中状态
                    $('.quanxuan').attr("checked",false);
                };
                function cailiaotankuang(obj) {
                    ajaxs('/api/matperson/loadGysFeedSel.do','post',{'type':'b','feed_Code1':obj.data.feed_Code,'p':getCookie('yanzheng')},function (data) {
                        //console.log(data)
                        var datas=data.data;
                        $('.xuanzhong table tbody').html('');
                        $('.beixuan table tbody').html('');
                        for(var i=0;i<datas.length;i++){
                            dizhi=datas[0].f_adr;
                            $('.xuanzhong table tbody').append('<tr id="'+datas[i].id+'" mat_id="'+datas[i].mat_id+'" idang="'+datas[i].mat_Price+'" f_adr="'+datas[i].f_adr+'" danwei="'+datas[i].mat_bit+'" nums="'+datas[i].fv_Num+'" guiges="'+datas[i].mat_Spec+'" names="'+datas[i].mat_Name+'">' +
                                '                                    <th style="text-align: center;width: 100px;">' +
                                '                                        <div class="layui-form-item" pane="">' +
                                '                                            <div class="layui-input-block">' +
                                '                                                <input type="checkbox" name="like1[write]" lay-filter="filter" lay-skin="primary" title=\'\'>' +
                                '                                                <input type="hidden" name="feed_Code" lay-filter="filter" lay-skin="primary" value="'+ obj.data.feed_Code +'">' +
                                '                                                <input type="hidden" name="rm_Code" lay-filter="filter" lay-skin="primary" value="001">' +
                                '                                            </div>' +
                                '                                        </div>' +
                                '                                    </th>' +
                                '                                    <th>'+datas[i].mat_Name+'</th>' +
                                '                                    <th>'+datas[i].mat_Spec+'</th>' +
                                '                                    <th>'+datas[i].feed_Num+'</th>' +
                                '                                    <th>'+datas[i].fv_Num+'</th>' +
                                '                                    <th>'+datas[i].mat_bit+'</th>' +
                                '                                </tr>')

                        };           //循环渲染页面数据
                        form.render();
                    })
                }
                cailiaotankuang(obj);
                uuids=obj.data.cc_uuid;
                $('.mask').show();
                $('._submit button').text('发货');
            }else if(layEvent==='look'){
                //console.log(obj)
                sessionStorage.UUid=obj.data.feed_Code;
                location.href='./cailiaoApplyDetails.html';
            };
        });
        form.on('submit(_subm)',function (data) {
            //console.log(data.field)
            var cailiao='';
            if( $('.beixuan tbody tr').length==0){
                layer.msg('请选择原料');
                return false;
            };
            $('.beixuan tbody tr').each(function () {
                cailiao+=$(this).attr('mat_id')+','+$(this).children('.nums').children('.numson').val()+','+$(this).children('.nums').children('.inputs').val()+','+$(this).attr('idang')+','+'0'+','+$(this).attr('id')+'|';
            });
            cailiao=cailiao.substr(0,cailiao.length-1);
            //console.log(cailiao)
            data.field.lRdetail=cailiao;
            data.field.cc_UUID  =uuids;
            data.field.r_adr=dizhi;
            data.field.p=getCookie('yanzheng');
            console.log(data.field);
            Btnon('.tijiao');      //  禁止按钮点击
            layer.confirm('是否立即打印单据？', {
                btn: ['是的立即打印','暂时不需要打印'] //按钮
            }, function(){      //点击是的立即打印时需要打印一份单据并提交     （打印功能暂未添加）
                //TODO://暂时注释 formAlertAjax('/api/supply/builFeedManagerVali.do',data.field,'.tijiao');
                daochu(1123);
                //需要打印新的表格，先跳转页面，而后刷新页面
                /*$.ajax({
                    type:'post',
                    url:urls+'/api/supply/builFeedManagerVali.do',
                    data:data.field,
                    success:function (res) {
                        console.log(res)
                        if(res.code==0){
                            layer.msg(res.msg);

                            setTimeout(function () {                //定时，两秒后重载当前文档
                                window.open(urls+'/api/print/printConcract.do?cc_UUID='+uuids,'no');
                                location.reload();
                            },2000)


                        }else if(res.code==1){
                            layer.msg(res.msg);
                            Btnoff('.tijiao');      //开放 按钮点击
                        }else{
                            layer.msg(res.msg);
                            Btnoff('.tijiao');      //开放 按钮点击
                        }
                    },
                    error:function (data) {
                        layer.msg('网络异常');
                        Btnoff('.tijiao');      //开放 按钮点击
                    }
                })*/
            }, function(){      //点击暂时不需要打印时   直接提交
                formAlertAjax('/api/supply/builFeedManagerVali.do',data.field,'.tijiao');
            });

//            formAlertAjax('/api/supply/builFeedManagerVali.do',data.field,'.tijiao');         //暂时禁用
            return false;
        });
        $("[name='feed_Code']").blur(function () {
            //console.log($(this).val()!= $("[name='namespan']").val())
            if($(this).val()== $("[name='namespan']").val()){
                return;
            };
            ajaxs('/api/public/cheName.do','get',{'type':3,'name':$(this).val()},function (data) {
                //console.log(data)
                if(data.code==0){
                    if(data.data=='1'){
                        layer.msg('申请单号已存在 请重新输入');
                        $('.tijiao').attr('disabled','true').addClass('layui-btn-disabled');//禁止提交按钮点击
                    }else{
                        layer.msg('申请单号可用');
                        $('.tijiao').removeAttr('disabled').removeClass('layui-btn-disabled');//禁止提交按钮点击
                    };
                };
            });
        });
        inputs();
        //材料添加
        $('.material_C').click(function () {
            var _dom=$(this).parents('.materialone').html();                //获取marerialone的页面html结构 用以下文塞进结构内部
            $('.materialone').after('<div class="material">'+_dom+'</div>');    //在materialone之后插入html结构
            form.render();              //刷新页面
        });

    })




</script>
</body>
</html>